package com.sky.controller.user;

import com.sky.pojo.Category;
import com.sky.pojo.Dish;
import com.sky.pojo.Setmeal;
import com.sky.result.Result;
import com.sky.service.admin.CategoryService;
import com.sky.service.admin.DishService;
import com.sky.service.admin.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description CategoryController
 * @Author lyh
 * @Date 2024-09-30
 */
@RestController("userCategoryController")
@RequestMapping("/user")
@Api(tags = "用户端菜品展示")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private DishService dishService;
    @Autowired
    private SetmealService setmealService;
    /**
     * 菜品分类
     * @return
     */
    @GetMapping("/category/list")
    @ApiOperation("菜品分类")
    public Result<List<Category>> getCategoryList(){
      List<Category> list=categoryService.list1();
      return Result.success(list);
    }

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @GetMapping("/dish/list")
    @ApiOperation("根据分类id查询菜品")
    public Result<List<DishVO>> dishList(Long categoryId){
        List<DishVO> list=dishService.list1(categoryId);
        return Result.success(list);
    }
    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @Cacheable(value="setmeal",key="#categoryId")
    @GetMapping("/setmeal/list")
    @ApiOperation("根据分类id查询套餐")
    public Result<List<Setmeal>> setmealList(Long categoryId){
        List<Setmeal> list=setmealService.list(categoryId);
        return Result.success(list);
    }

    /**
     * 根据套餐id查询包含的菜品
     * @return
     */
    @GetMapping("/setmeal/dish/{setmealId}")
    @ApiOperation("根据套餐id查询包含的菜品")
    public Result<List<DishItemVO>> list(@PathVariable Long setmealId){
      List<DishItemVO> list=setmealService.getBysetmealId(setmealId);
      return Result.success(list);
    }
}
